
export const baseUrl="http://192.168.16.199:8010/mini/"
export const imgBaseUrl="https://www.hotspotin.top/mall/manager/file/download/"//(错的别用)

function promiseFn(url,method,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      url: baseUrl+url,
      method,
      data:data ? data : {},
      success:res=>{
        resolve(res)
      },
      fail:error=>{
        reject(error)
      }
    })
  })
}
async function httpRequest(url,method,data){
  try{
    let res=await promiseFn(url,method,data)
    if(res.data.code==200){
      return res.data
    }
  }catch(err){
    wx.showToast({
      title: '请求失败',
      icon:"error"
    })
  }
  
}

export class request{
  static async postRequest(url,data){
    return await httpRequest(url,"POST",data)
  }
  static async getRequest(url,data){
    return await httpRequest(url,"GET",data)
  }
}